package com.zcn.io.web.controller;

import cn.hutool.core.bean.BeanUtil;
import com.zcn.io.common.entity.OrderMain;
import com.zcn.io.common.entity.TrusteeshipDetail;
import com.zcn.io.common.pojo.CommonResult;
import com.zcn.io.web.api.vo.TrusteeshipDetailVo;
import com.zcn.io.web.service.OrderService;
import com.zcn.io.web.service.TrusteeshipDetailService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc:
 * @author: 202438 邱建伟
 * @date: 2024/10/2 15:47
 * @Copyright (c) 2024, 江苏金恒信息科技股份有限公司
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/trusteeshipDetail")
public class TrusteeshipDetailController {

    private final TrusteeshipDetailService trusteeshipDetailService;

    private final OrderService orderService;

//    @GetMapping("/list")
//    public CommonResult<Page<TrusteeshipDetailVo>> list(TrusteeshipDetailQuery query) {
//        trusteeshipDetailService.list(query);
//        return CommonResult.success(page);
//
//
//    }

    @GetMapping("/listAllByOrderId")
    public CommonResult<List<TrusteeshipDetailVo>> listAllByOrderId(String orderId) {
        return CommonResult.success(trusteeshipDetailService.listAllByOrderId(orderId));
    }

    @GetMapping("/getById")
    public CommonResult<TrusteeshipDetail> getById(String id) {
        return CommonResult.success(trusteeshipDetailService.getById(id));
    }

    @PostMapping("/save")
    public CommonResult<String> save(@RequestBody TrusteeshipDetailVo trusteeshipDetail) {
        trusteeshipDetailService.save(trusteeshipDetail);
        return CommonResult.success("保存成功");
    }

    @PostMapping("/saveInfo")
    public CommonResult<String> saveInfo(@RequestBody TrusteeshipDetail trusteeshipDetail) {
        trusteeshipDetailService.saveInfo(trusteeshipDetail);
        return CommonResult.success("保存成功");
    }

    @PostMapping("/updateById")
    public CommonResult<String> updateById(@RequestBody TrusteeshipDetailVo trusteeshipDetail) {
        trusteeshipDetailService.updateById(trusteeshipDetail);
        return CommonResult.success("更新成功");
    }

    @DeleteMapping("/deleteById")
    public CommonResult<String> deleteById(String id) {
        trusteeshipDetailService.deleteById(id);
        return CommonResult.success("删除成功");
    }

    /**
     * @desc: 更新托管身份信息以及托管明细中的资料信息
     * @author 202438 邱建伟
     * @date 2025/5/2 18:56
     */
    @PostMapping("/updateNativePlaceHandleAndInfo")
    public CommonResult<String> updateNativePlaceHandleAndInfo(@RequestBody TrusteeshipDetailVo trusteeshipDetailVo) {
        OrderMain orderMain = BeanUtil.copyProperties(trusteeshipDetailVo, OrderMain.class);
        orderMain.setId(trusteeshipDetailVo.getOrderId());
        orderService.updateNativePlaceAndOnlineInfoHandle(orderMain);
        //更新托管明细中的资料信息
        trusteeshipDetailService.updateInfo(trusteeshipDetailVo);
        return CommonResult.success("编辑成功");
    }


}
